/*
 * @Description: 
 * @Author: hanyu
 * @Date: 2022-03-08 19:29:01
 * @LastEditTime: 2022-03-19 11:18:03
 * @LastEditors: hanyu
 */
import {allApi} from '@/api/allApi'
export default {
    state: {
        webInfo: null, // 网站信息
        activeTab: null, // 顶部被激活的tab
        searchTxt: '', // 搜索时的参数
    },
    mutations: {
        // 设置tab
        SET_ACTIVE_TAB(state, activeTab) {
            state.activeTab = activeTab
        },
        // 设置搜索字段
        SET_SEARCH_TXT(state, searchTxt) {
            state.searchTxt = searchTxt
        },
        // 设置网站信息
        SET_WEB_INFO(state, webInfo){
            state.webInfo = webInfo
        }
    },
    actions: {
        // 获取网站信息
        async getWebInfo({
            commit
        }) {
            try {
                const res = await allApi.IndexWebinfo()
                document.title = res.data.website_name
                commit('SET_WEB_INFO', res.data)
            } catch (error) {
                console.log(error);
            }
        },
        changeInputSearch({
            commit
        }, searchTxt) {
            commit('SET_SEARCH_TXT', searchTxt)
        },
        setActiveTab({
            commit
        }, activeTab) {
            commit('SET_ACTIVE_TAB', activeTab)
        }
    }

}